#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<string>

using namespace std;

class Solution
{

    const string thousands[4] = { "", "M", "MM", "MMM" };
    const string hundreds[10] = { "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" };
    const string tens[10] = { "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" };
    const string ones[10] = { "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" };

    string GetStr(int& num)
    {
        if (num >= 1000)
        {
            num -= 1000;
            return "M";
        }
        else if (num >= 900)
        {
            num -= 900;
            return "CM";
        }
        else if (num >= 500)
        {
            num -= 500;
            return "D";
        }
        else if (num >= 400)
        {
            num -= 400;
            return "CD";
        }
        else if (num >= 100)
        {
            num -= 100;
            return "C";
        }
        else if (num >= 90)
        {
            num -= 90;
            return "XC";
        }
        else if (num >= 50)
        {
            num -= 50;
            return "L";
        }
        else if (num >= 40)
        {
            num -= 40;
            return "XL";
        }
        else if (num >= 10)
        {
            num -= 10;
            return "X";
        }
        else if (num >= 9)
        {
            num -= 9;
            return "IX";
        }
        else if (num >= 5)
        {
            num -= 5;
            return "V";
        }
        else if (num >= 4)
        {
            num -= 4;
            return "IV";
        }
        else
        {
            num -= 1;
            return "I";
        }
    }

public:

    string intToRoman(int num)
    {
        /*string s = "";
        while (num > 0)
        {
            if (num >= 1000)
            {
                s += "M";
                num -= 1000;
            }
            else if (num >= 900)
            {
                s += "CM";
                num -= 900;
            }
            else if (num >= 500)
            {
                s += "D";
                num -= 500;
            }
            else if (num >= 400)
            {
                s += "CD";
                num -= 400;
            }
            else if (num >= 100)
            {
                s += "C";
                num -= 100;
            }
            else if (num >= 90)
            {
                s += "XC";
                num -= 90;
            }
            else if (num >= 50)
            {
                s += "L";
                num -= 50;
            }
            else if (num >= 40)
            {
                s += "XL";
                num -= 40;
            }
            else if (num >= 10)
            {
                s += "X";
                num -= 10;
            }
            else if (num >= 9)
            {
                s += "IX";
                num -= 9;
            }
            else if (num >= 5)
            {
                s += "V";
                num -= 5;
            }
            else if (num >= 4)
            {
                s += "IV";
                num -= 4;
            }
            else if (num >= 1)
            {
                s += "I";
                num -= 1;
            }
        }
        return s;*/

        /*string res;
        while (num > 0)
        {
            res += GetStr(num);
        }
        return res;*/

        
        return thousands[num / 1000] + hundreds[num % 1000 / 100] + tens[num % 100 / 10] + ones[num % 10];

    }
};

int main()
{
    Solution S;
    cout<<S.intToRoman(7856);
    return 0;
}